/*

 * Copyright (C) 2021 Huawei Device Co., Ltd.

 * Licensed under the Apache License, Version 2.0 (the "License");

 * you may not use this file except in compliance with the License.

 * You may obtain a copy of the License at

 *

 *     http://www.apache.org/licenses/LICENSE-2.0

 *

 * Unless required by applicable law or agreed to in writing, software

 * distributed under the License is distributed on an "AS IS" BASIS,

 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

 * See the License for the specific language governing permissions and

 * limitations under the License.

 */
package me.aartikov.alligator.helpers;

import ohos.aafwk.ability.fraction.FractionManager;
import ohos.aafwk.ability.fraction.FractionScheduler;
import ohos.aafwk.content.Intent;

import ohos.agp.window.dialog.CommonDialog;

public class DialogFraction extends MiFraction {
    boolean isRemove;
    Intent intent;

    /**
     * 将当前fraction从manage中移除
     */
    public void dismiss() {
        isRemove = false;
        getFractionAbility().getFractionManager().startFractionScheduler().remove(this).submit();
    }

    /**
     * 将当前fraction添加至manager中
     * @param mFragmentManager fraction管理
     */
    public void show(FractionManager mFragmentManager) {
        isRemove = true;
        FractionScheduler scheduler = mFragmentManager.startFractionScheduler();
        scheduler.show(this).submit();
    }

    /**
     * 判断是否移除
     * @return 是否移除
     */
    public boolean isRemoving() {
        return isRemove;
    }

    /**
     * 获取到一个弹窗
     * @return CommonDialog
     */
    public CommonDialog getDialog() {
        return new CommonDialog(getFractionAbility());
    }

    /**
     * 设置当前fraction携带的数据
     * @param intent 数据
     */
    public void setArguments(Intent intent) {
        this.intent = intent;
    }

    /**
     * 获取当前fraction的携带数据
     * @return Intent
     */
    public Intent getArguments() {
        return intent;
    }

    /**
     * 初始化完成后调用
     */
    @Override
    public void setInitialFragmentIfRequired() {

    }
}
